//  this library.
import 'package:hktk_app/ienum/home/column_position_enum.dart';
import 'package:hktk_app/model/home/banner_model.dart';
import 'package:hktk_app/model/home/category_records_model.dart';
import 'package:hktk_app/model/home/column_model.dart';
import 'package:hktk_app/model/home/latest_model.dart';
import 'package:hktk_app/model/home/resource_model.dart';
import 'package:hktk_app/model/page/resource_page_model.dart';
import 'package:hktk_app/util/dao_util.dart';

/// 首页相关接口
class HomeDao {
  /// 根据考试id获取最近考试时间
  static Future<LatestModel> latestDate(String examId) async {
    String url = "/exam/calendar/latest-date?examId=$examId";
    // 发送请求
    var data = await httpGET(url: url, tips: "根据考试id获取最近考试时间");
    return LatestModel.fromJson(data);
  }

  /// 根据科目拉去栏目 并判断用户/机构是否有其权限，不登录也可
  static Future<List<ColumnModel>> columnByCategory({
    required int categoryId,
    required int groupId,
    required ColumnPositionEnum columnEnum,
  }) async {
    String url =
        "/exam/column/column-by-category?categoryId=$categoryId&groupId=$groupId&columnPosition=${columnEnum.code}";
    // 发送请求
    var data = await httpGET(url: url, tips: "根据科目拉去栏目 并判断用户/机构是否有其权限，不登录也可");
    if (data is List<dynamic>) {
      return data.map((dynamic map) => ColumnModel.fromJson(map)).toList();
    } else {
      return <ColumnModel>[];
    }
  }

  /// 获取广告列表
  static Future<List<BannerModel>> getBannerList() async {
    String url = "/banners/list?positionCode=APP_CENTER_ADV";
    // 发送请求
    var data = await httpGET(url: url, tips: "获取广告列表");
    if (data is List<dynamic>) {
      return data.map((dynamic map) => BannerModel.fromJson(map)).toList();
    } else {
      return <BannerModel>[];
    }
  }

  // size : 每页条数
  // current : 页数
  // columnId : 栏目id
  // industryCode : 行业id
  // examId : 考试id
  // categoryId : 科目id
  /// 根据栏目拉取资料列表
  static Future<ResourcePageModel<ResourceModel>> materialByColumnId({
    required int size,
    required int current,
    required String columnId,
    required String industryCode,
    required String examId,
    required int categoryId,
  }) async {
    String url =
        "/material/info/material-by-columnId?size=$size&current=$current&columnId=$columnId&industryCode=$industryCode&examId=$examId&categoryId=$categoryId";
    // 发送请求
    var data = await httpGET(url: url, tips: "根据栏目拉取资料列表");
    return ResourcePageModel.fromJson(data);
  }

  /// 获取科目下做题数据
  static Future<CategoryRecordsModel> categoryRecords({
    required int categoryId,
    required String examId,
    required String industryCode,
  }) async {
    String url =
        "/exam/records/category-records?categoryId=$categoryId&examId=$examId&industryCode=$industryCode";
    // 发送请求
    var data = await httpGET(url: url, tips: "获取科目下做题数据");
    if (data != null) {
      return CategoryRecordsModel.fromJson(data);
    }
    return CategoryRecordsModel();
  }

  static Future<dynamic> getVideoTrial({
    required int? categoryId,
  }) async{
    String url="/exam/column/getVideoTrial?categoryId=$categoryId";
    var data = await httpGET(url: url, tips: "获取免费视频");
    return data;
  }
}
